/*
 * Sample.hh
 *
 *  Created on: 17.04.2011
 *      Author: ed
 */

#ifndef SAMPLE_HH_
#define SAMPLE_HH_
#include "globals.hh"
#include "ostream"
using namespace std;
class Sample
{
public:
	Sample(G4int LAbs):lAbs(LAbs)
	{
		lCSum = 0;
		lCSumSqr = 0;
		nExperiments = 0;
		k = 0;
		dispersion = 0;
		error = 0;
		lC = 0;
		relativeError = 0;
	}
	inline G4int GetLAbs() const {return lAbs;}
	inline G4int GetNExperiments() const {return nExperiments;}
	inline G4double GetLC() const {return lC;}
	inline G4double GetDispersion() const {return dispersion;}
	inline G4double GetError() const {return error;}
	inline G4double GetRelativeError() const{return relativeError;}
	friend ostream& operator<<(ostream& os, const Sample& sample)
	{
		os<<"LC: "<<sample.GetLC()<<" LAbs: "<<sample.lAbs<<", error: "<<sample.GetError()
				<<"relative error: "<<sample.GetRelativeError()
				<<", n: "<<sample.GetNExperiments()
				<<", k:"<<sample.k<<std::endl;
		return os;
	}
	G4double k;
	void AddExperiment(G4double result)
	{
		nExperiments++;
		lCSum += result;
		lC = lCSum/nExperiments;
		lCSumSqr += result*result;
		dispersion = lCSumSqr/nExperiments-lC*lC;
		error = std::sqrt(dispersion);
		relativeError = error/lC;
	}
	virtual ~Sample(){;};

private:
	G4int lAbs,nExperiments;
	G4double lC,dispersion,error,relativeError;
	G4double lCSum,lCSumSqr;
};

#endif /* SAMPLE_HH_ */
